import { LessonService } from "@/shared/api/api.lesson";
import { ModelServise } from "@/shared/api/api.model";
import { ILesson, IModel } from "@/shared/interfaces";
import { QueryClient, useMutation, useQueries, useQuery } from "@tanstack/react-query";
import { AxiosError } from "axios";
import { useEffect, useRef, useState } from "react";



export function useGetAllModels() {
    const queryClient = new QueryClient


    const getModelById = useQuery<IModel[], AxiosError<{ message: string }>>(
        {
            queryKey: ['models'],
            queryFn: () => ModelServise.getAll(),
            retry: 3,
            placeholderData: (previousData) => previousData,
        }, queryClient
    );

    const errorMessage = getModelById.error?.response?.data.message

    return {
        isSuccess: getModelById.isSuccess,
        isPending: getModelById.isPending,
        refetch: getModelById.refetch,
        errorMessage,
        models: getModelById.data
    };
}